# 类的执行过程
# class Custom:
#     def __init__(self):
#         print("asdasdasd")
#
#     def __new__(cls, *args, **kwargs):
#         print("new method")
#         return object.__new__(cls, *args, **kwargs)
#
#
# if __name__ == "__main__":
#     Custom()

# 类的特殊的方法
# class Custom:
#     pass
#
# if __name__ == "__main__":
#     print(dir(Custom()))

# class Point:
#     def __init__(self, x, y):
#         self.x = x
#         self.y = y
#
#     def __lt__(self, other):
#         return self.x < other.x
#
#     def __gt__(self, other):
#         return self.y > other.y
#
#
# if __name__ == "__main__":
#     pa = Point(1, 1)
#     pb = Point(0, 0)
#     print(pa < pb)
#     print(pa > pb)

# class Point:
#     def __init__(self, x, y):
#         self.x = x
#         self.y = y
#
#     def __add__(self, other):
#         return Point(self.x + other.x, self.y + other.y)
#
#     def info(self):
#         print(self.x, self.y)
#
#
# if __name__ == "__main__":
#     pa = Point(1, 2)
#     pb = Point(2, 3)
#     pc = pa + pb
#     pc.info()


# 类的多态属性
# class Animal:
#     def move(self):
#         print("Animal is move")
#
#
# class Dog(Animal):
#     def move(self):
#         print("Dog is move")
#
#
# class Cat:
#     pass
#
#
# def movefunc(obj):
#     obj.move()
#
#
# a = Animal()
# d = Dog()
#
# movefunc(d)


# 类的设计模式  -- 单例模式
# class SingleClass:
#     def __init__(self, x=0):
#         self.x = x
#
#
# sc = SingleClass()
#
#
# def sec():
#     print(sc.x)
#     sc.x = 10
#     print(sc.x)
#
#
# def tec():
#     print(sc.x)
#     sc.x = 9
#     print(sc.x)
#
# if __name__ == "__main__":
#     sec()
#     tec()

# 工厂模式
# class A:
#     pass
# class B:
#     pass
#
# class MyFactory:
#     def get_instance(self,cls):
#         return cls()
#
# if __name__ == "__main__":
#     f  = MyFactory()
#     print(type(f.get_instance(A)))
#     print(type(f.get_instance(B)))


# 策略模式
# class MoveAble:
#     def move(self):
#         print("able move...")
# class MoveOnFoot:
#     def move(self):
#         print("on foot move ...")
# class MoveOnWheel:
#     def move(self):
#         print("on wheel move...")
#
# class MoveObj:
#     def set_move(self,moveable):
#         self.moveable = moveable
#     def move(self):
#         self.moveable.move(self)
# if __name__ == '__main__':
#     m = MoveObj()
#     m.set_move(MoveAble)
#     m.move()
#
#     m = MoveObj()
#     m.set_move(MoveOnFoot)
#     m.move()
#
#     m = MoveObj()
#     m.set_move(MoveOnWheel)
#     m.move()

# 装饰模式
# class BeDeco:
#     def be_edit_fun(self):
#         print("source fun")
#
#     def be_keep_fun(self):
#         print("keep fun")
#
#
# class Decorate:
#     def __init__(self, dec):
#         self._dec = dec()
#
#     def be_edit_fun(self):
#         print("start...")
#         self._dec.be_edit_fun()
#
#     def be_keep_fun(self):
#         print("start...")
#         self._dec.be_keep_fun()
#
# if __name__ == "__main__":
#     b = Decorate(BeDeco)
#     b.be_edit_fun()
#     b.be_keep_fun()

# 装饰模式2
# def deco(a_class):
#     class NewClass:
#         def __init__(self,age,color):
#             self.age = age
#             self.color = color
#         def display(self):
#             print(self.color)
#             print(self.age)
#     return NewClass
# @deco
# class Cat:
#     def __init__(self,age):
#         self.age = age
#     def display(self):
#         print(self.age)
#
# if __name__ == '__main__':
#     c = Cat(18,"blue")
#     c.display()

# 构建复杂的类
# class Shape:
#     def __init__(self,cvns,points):
#         self.cvns = cvns
#         self.points = points
#         self.pid = None
#     def delete(self):
#         if self.pid:
#             self.cvns.delete(self.pid)
# class ShapeAngles(Shape):
#     def __init__(self,cvns,points,angles=(10,170)):
#         super().__init__(cvns,points)
#         self.angles = {"start":angles[0],'extent':angles[1]}
# class HatTop(Shape):
#     def draw(self):
#         self.pid = self.cvns.create_oval(*self.points)
# class HatButtom:
#     def draw(self):
#         self.pid = self.cvns.create_polygon(*self.points)
# class Hat:
#     def __init__(self,cvns,start_point,w,h):
#         self.cvns = cvns
#         self.start_points = start_point
#         self.w = w
#         self.h = h
#         self.ht = HatTop(self.cvns,self.ht_cacu())
#         self.hb = HatButtom(self.cvns,self.hb_cacu())
#     def draw(self):
#         self.ht.draw()
#         self.hd.draw()
#     def delete(self):
#         self.ht.delete()
#         self.hd.delete()
#     def ht_cacu(self):
#         r = self.h / 3 / 2
#         x1 = self.start_points[0] + self.w / 2  - r






